package cn.iocoder.yudao.module.system.controller.admin.gugu.vo;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * 直接参数分组查询响应 VO
 */
@Schema(description = "直接参数分组查询响应 VO")
@Data
public class DirectParamsGroupRespVO {

    @Schema(description = "分组类型：school-按学校分组，major-按专业分组，none-不分组", example = "school")
    private String groupType;

    @Schema(description = "学校分组数据（当groupType为school时返回）")
    private PageResult<SchoolGroupData> schoolGroups;

    @Schema(description = "专业分组数据（当groupType为major时返回）")
    private PageResult<MajorGroupData> majorGroups;

    @Schema(description = "按冲稳保分类的学校分组数据（当groupType为school时返回）")
    private SchoolClassificationData schoolClassification;

    @Schema(description = "按冲稳保分类的专业分组数据（当groupType为major时返回）")
    private MajorClassificationData majorClassification;

    @Schema(description = "查询信息")
    private String queryInfo;

    @Schema(description = "总数量", example = "100")
    private Integer totalCount;

    @Schema(description = "页码", example = "1")
    private Integer pageNo;

    @Schema(description = "每页大小", example = "10")
    private Integer pageSize;

    @Schema(description = "总页数", example = "10")
    private Integer totalPages;

    /**
     * 学校分组数据
     */
    @Schema(description = "学校分组数据")
    @Data
    public static class SchoolGroupData {
        @Schema(description = "学校UUID", example = "uuid-123")
        private String schoolUuid;

        @Schema(description = "学校名称", example = "北京大学")
        private String schoolName;

        @Schema(description = "学校基础信息")
        private SchoolBasicInfo schoolInfo;

        @Schema(description = "学校等级分类", example = "rush", allowableValues = {"rush", "stable", "safe"})
        private String levelType;

        @Schema(description = "冲刺专业数量", example = "10")
        private Integer rushCount;

        @Schema(description = "稳妥专业数量", example = "15")
        private Integer stableCount;

        @Schema(description = "保底专业数量", example = "8")
        private Integer safeCount;

        @Schema(description = "总专业数量", example = "33")
        private Integer totalCount;

        @Schema(description = "冲刺专业列表（仅当includeMajorDetails=true时返回）")
        private List<MajorAdmissionInfo> rushMajors;

        @Schema(description = "稳妥专业列表（仅当includeMajorDetails=true时返回）")
        private List<MajorAdmissionInfo> stableMajors;

        @Schema(description = "保底专业列表（仅当includeMajorDetails=true时返回）")
        private List<MajorAdmissionInfo> safeMajors;

        @Schema(description = "是否包含专业详情数据", example = "false")
        private Boolean hasMajorDetails;

        @Schema(description = "该校24年所有专业招生计划人数总和", example = "500")
        private Integer totalEnrollmentPlan;

        @Schema(description = "该校所有专业中的录取最低分", example = "580")
        private String lowestAdmissionScore;

        @Schema(description = "该校所有专业中的最低位次", example = "15000")
        private String lowestAdmissionRank;
    }

    /**
     * 专业分组数据
     */
    @Schema(description = "专业分组数据")
    @Data
    public static class MajorGroupData {
        @Schema(description = "专业名称", example = "计算机科学与技术")
        private String majorName;

        @Schema(description = "专业类别", example = "工学")
        private String classOne;

        @Schema(description = "专业子类", example = "计算机类")
        private String classTwo;

        @Schema(description = "专业等级分类", example = "rush", allowableValues = {"rush", "stable", "safe"})
        private String levelType;

        @Schema(description = "冲刺学校数量", example = "5")
        private Integer rushCount;

        @Schema(description = "稳妥学校数量", example = "8")
        private Integer stableCount;

        @Schema(description = "保底学校数量", example = "12")
        private Integer safeCount;

        @Schema(description = "总学校数量", example = "25")
        private Integer totalCount;

        @Schema(description = "冲刺学校列表")
        private List<MajorAdmissionInfo> rushSchools;

        @Schema(description = "稳妥学校列表")
        private List<MajorAdmissionInfo> stableSchools;

        @Schema(description = "保底学校列表")
        private List<MajorAdmissionInfo> safeSchools;
    }

    /**
     * 按冲稳保分类的学校数据
     */
    @Schema(description = "按冲稳保分类的学校数据")
    @Data
    public static class SchoolClassificationData {
        @Schema(description = "冲刺学校列表")
        private List<SchoolGroupData> rushSchools;

        @Schema(description = "稳妥学校列表")
        private List<SchoolGroupData> stableSchools;

        @Schema(description = "保底学校列表")
        private List<SchoolGroupData> safeSchools;

        @Schema(description = "冲刺学校数量", example = "5")
        private Integer rushCount;

        @Schema(description = "稳妥学校数量", example = "8")
        private Integer stableCount;

        @Schema(description = "保底学校数量", example = "12")
        private Integer safeCount;

        @Schema(description = "总学校数量", example = "25")
        private Integer totalCount;
    }

    /**
     * 按冲稳保分类的专业数据
     */
    @Schema(description = "按冲稳保分类的专业数据")
    @Data
    public static class MajorClassificationData {
        @Schema(description = "冲刺专业列表")
        private List<MajorGroupData> rushMajors;

        @Schema(description = "稳妥专业列表")
        private List<MajorGroupData> stableMajors;

        @Schema(description = "保底专业列表")
        private List<MajorGroupData> safeMajors;

        @Schema(description = "冲刺专业数量", example = "5")
        private Integer rushCount;

        @Schema(description = "稳妥专业数量", example = "8")
        private Integer stableCount;

        @Schema(description = "保底专业数量", example = "12")
        private Integer safeCount;

        @Schema(description = "总专业数量", example = "25")
        private Integer totalCount;
    }

    /**
     * 学校基础信息
     */
    @Schema(description = "学校基础信息")
    @Data
    public static class SchoolBasicInfo {
        @Schema(description = "学校UUID", example = "uuid-123")
        private String schoolUuid;

        @Schema(description = "学校名称", example = "北京大学")
        private String collegeName;

        @Schema(description = "省份", example = "北京")
        private String province;

        @Schema(description = "城市", example = "北京市")
        private String city;

        @Schema(description = "学校类型", example = "综合类")
        private String collegeType;

        @Schema(description = "是否985", example = "true")
        private Boolean is985;

        @Schema(description = "是否211", example = "true")
        private Boolean is211;

        @Schema(description = "是否双一流", example = "true")
        private Boolean isDualClass;

        @Schema(description = "封面图片", example = "http://example.com/cover.jpg")
        private String coverImage;
    }

    /**
     * 专业录取信息
     */
    @Schema(description = "专业录取信息")
    @Data
    public static class MajorAdmissionInfo {
        @Schema(description = "省份名称", example = "北京")
        private String provinceName;

        @Schema(description = "学校UUID", example = "uuid-123")
        private String schoolUUID;

        @Schema(description = "学校名称", example = "北京大学")
        private String schoolName;

        @Schema(description = "专业名称", example = "计算机科学与技术")
        private String majorName;

        @Schema(description = "专业代码", example = "080901")
        private String majorCode;

        @Schema(description = "年份", example = "2024")
        private Integer year;

        @Schema(description = "最高分", example = "680")
        private String highScore;

        @Schema(description = "平均分", example = "670")
        private String averageScore;

        @Schema(description = "最低分", example = "660")
        private String lowestScore;

        @Schema(description = "最低位次", example = "1000")
        private String lowestSection;

        @Schema(description = "批次名称", example = "本科一批")
        private String batchName;

        @Schema(description = "类型名称", example = "物理类")
        private String typeName;

        @Schema(description = "专业分", example = "0")
        private String proScore;

        @Schema(description = "选科要求", example = "物理+化学")
        private String subjectSelection;

        @Schema(description = "专业标准代码", example = "0809")
        private String majorStandardCode;

        @Schema(description = "历史年份数据（2021-2023年）")
        private List<HistoricalYearData> historicalData;

        @Schema(description = "历史数据是否正在加载", example = "false")
        private Boolean historicalDataLoading;

        @Schema(description = "招生计划数据")
        private List<CollegeEnrollmentPlanInfo> enrollmentPlanData;

        @Schema(description = "招生计划数据是否正在加载", example = "false")
        private Boolean enrollmentPlanDataLoading;

        /**
         * 重写 equals 方法，只比较核心唯一标识字段
         * 用于分组查询中的冲稳保分类判断
         * 使用 Objects.equals 避免空指针和潜在的递归调用
         */
        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            MajorAdmissionInfo that = (MajorAdmissionInfo) o;

            // 使用 Objects.equals 进行安全比较，避免空指针和递归调用
            return Objects.equals(provinceName, that.provinceName) &&
                   Objects.equals(schoolUUID, that.schoolUUID) &&
                   Objects.equals(majorName, that.majorName) &&
                   Objects.equals(year, that.year) &&
                   Objects.equals(lowestScore, that.lowestScore);
        }

        /**
         * 重写 hashCode 方法，与 equals 方法保持一致
         * 使用 Objects.hash 避免潜在问题
         */
        @Override
        public int hashCode() {
            return Objects.hash(provinceName, schoolUUID, majorName, year, lowestScore);
        }
    }

    /**
     * 历史年份数据
     */
    @Schema(description = "历史年份数据")
    @Data
    public static class HistoricalYearData {
        @Schema(description = "年份", example = "2023")
        private Integer year;

        @Schema(description = "最高分", example = "680")
        private String highScore;

        @Schema(description = "平均分", example = "670")
        private String averageScore;

        @Schema(description = "最低分", example = "660")
        private String lowestScore;

        @Schema(description = "最低位次", example = "1000")
        private String lowestSection;
    }

    /**
     * 招生计划信息
     */
    @Schema(description = "招生计划信息")
    @Data
    public static class CollegeEnrollmentPlanInfo {
        @Schema(description = "年份", example = "2024")
        private Integer year;

        @Schema(description = "招生计划数", example = "50")
        private String enrollmentPlan;

        @Schema(description = "学费", example = "5000")
        private String tuition;

        @Schema(description = "选科要求", example = "物理+化学")
        private String courseSelectionRequirements;

        @Schema(description = "专业备注")
        private String majorRemarks;

        @Schema(description = "专业组", example = "175118")
        private String specialGroup;

        @Schema(description = "专业代码", example = "030101K")
        private String specialCode;

        @Schema(description = "专业组名称", example = "（01）")
        private String specialGroupName;

        @Schema(description = "学制年限", example = "4")
        private String inSchoolYears;

        @Schema(description = "专业大类", example = "工学")
        private String classOne;

        @Schema(description = "专业小类", example = "计算机类")
        private String classTwo;

        @Schema(description = "录取批次", example = "本科一批")
        private String batchName;

        @Schema(description = "文理综合类别", example = "理科")
        private String type;

        @Schema(description = "学校名称", example = "北京大学")
        private String schoolName;

        @Schema(description = "学校UUID", example = "uuid-123")
        private String schoolUuid;

        @Schema(description = "专业名称", example = "计算机科学与技术")
        private String collegeMajorName;

        @Schema(description = "专业代码", example = "080901")
        private String collegeMajorCode;

        @Schema(description = "省份名称", example = "北京")
        private String provinceName;
    }
}
